package at.jku.pervasive.simulator;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;

import at.jku.pervasive.Position;

public class UbisenseServerSimulatorThread extends Thread
{

	private final Socket clientSocket;
	private Position pos;
	private PositionBuffer buffer;

	public UbisenseServerSimulatorThread(PositionBuffer buffer, Socket clientSocket)
	{
		super();
		this.buffer = buffer;
		this.clientSocket = clientSocket;
	}

	@Override
	public void run()
	{
		try
		{
			OutputStream clientOutStream = this.clientSocket.getOutputStream();
			PrintWriter writer = new PrintWriter(clientOutStream);

			while (!this.clientSocket.isClosed())
			{
				Position nextPosition = this.buffer.get();
				writer.println(nextPosition);
				writer.flush();
			}
		} catch (IOException e)
		{
			e.printStackTrace();
		}
	}

	public PositionBuffer getPositionBuffer()
	{
		return buffer;
	}

}
